import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


public class Container {

	private static int maxWeight = 2000;
	
	private static void createAndShowGUI() {
		JFrame mainframe = new JFrame("Scale");
		mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		// Scale
		JPanel container = new JPanel(new BorderLayout(), true);
		container.setBorder(BorderFactory.createCompoundBorder(
			BorderFactory.createEmptyBorder(10,10,0,10),
			BorderFactory.createLoweredBevelBorder()
		));
		container.setPreferredSize(new Dimension(150,200));
		container.setFocusable(false);
		final ContainerGraph containerGraph = new ContainerGraph(maxWeight);
		container.add(containerGraph);

		// Spinner
		JPanel spinnerPanel = new JPanel(true);
		spinnerPanel.setPreferredSize(new Dimension(mainframe.getWidth(),30));
		final SpinnerNumberModel model = new SpinnerNumberModel(500, 0, maxWeight, 10);
		model.addChangeListener(new ChangeListener(){
			public void stateChanged(ChangeEvent e) {
				containerGraph.setCurrentWeight(((Integer) model.getValue()).intValue());
			}
		});
		JSpinner spinner = new JSpinner(model);
		JTextField tf = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
		tf.setColumns(3);
		tf.setEditable(false);
		spinnerPanel.add(new JLabel("Quantity"));
		spinnerPanel.add(spinner);
		
		// Build the GUI
		mainframe.add(container, BorderLayout.CENTER);
		mainframe.add(spinnerPanel, BorderLayout.SOUTH);
		mainframe.pack();
		mainframe.setMinimumSize(new Dimension(mainframe.getWidth(), mainframe.getHeight()));
		mainframe.setVisible(true);
	}

	public static void main(String[] args) {
		System.setProperty("sun.java2d.noddraw", Boolean.TRUE.toString());
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
	}

}
